package xzr2;

import java.util.LinkedList;

public class Worm {
    LinkedList<Node> node=new LinkedList<Node>();
    public static final int up=-10;
    public static final int down=10;
    public static final int right=-1;
    public static final int left=1;
    private int dir;
    public Worm(){
        node.add(new Node(4,9));
        node.add(new Node(4,10));
        node.add(new Node(5,10));
        node.add(new Node(6,10));
        node.add(new Node(6,11));
        node.add(new Node(7,11));
        node.add(new Node(8,11));
        dir=right;
    }
    public boolean baohan(int i,int j){
        return node.contains(new Node(i,j));
    }
    public void step(int dir){
        if(this.dir+dir==0){
            throw new RuntimeException("不能掉头");
        }
        this.dir=dir;
        step();
    }
    public void step(){
        Node n=node.getFirst();
        int i=n.getI()+dir/10;
        int j=n.getJ()+dir%10;
        n=new Node(i,j);
        node.addFirst(n);
        node.removeLast();
    }
}
